<?php 
	$pPageIsPublic = false;
	include '../_common.php';
	$_SESSION["m1"]="highlight";
	$_SESSION["m2"]="highlight-list";
	
	
	$pTitle  = 'New Highlight';
	$pButton = 'Save';
	$action  = 'add';
	$id 	 = intval($_REQUEST['id']);
	
	
	
	$objHi = new Highlight();
	$objHi ->setUid($id);
	if ($objHi ->load()) {
		$pTitle  = 'Edit Highlight';
		$pButton = 'Update';
		$action  = 'edit';
		//$locationMap = json_decode($objHi ->locationMap);
	}

		
	if ($_GET['action']== 'del') {
		if ($objHi ->isLoaded()) {
			$objHi ->removeImage('bgImage');
			$msg = "Picture has been deleted.";
		}
	}	
	
	if (isset($_POST['submit'])) {
		$objHi ->setAuto($_POST);
				
		$objHi ->uploadImage('ifile', 'bgImage');
		
		if ($_POST['action'] == 'edit') {
			$objHi ->getConnection();
			$objHi ->setUid($id);
			$objHi ->update();
			Tzn::redirect($_SERVER['PHP_SELF']."?id=". $objHi ->id, 'Highlight has been updated.');
		} elseif ($_POST['action'] == 'add') {
			$objHi ->add();
			Tzn::redirect($_SERVER['PHP_SELF']."?id=". $objHi ->id, 'Highlight has been added.');
		}
	}
	
	$dropdown = $objHi ->getDestinationTree();
?>
<?php include("header.php"); ?>
<script type="text/javascript">
$(document).ready(function(){
	$('#frmMain').validate();

	var $ele = $('input[name="destination"]');
	if ($ele.length > 0) {
		$('ul#categorymenu').addClass("mcdropdown_menu");
		$ele.mcDropdown("ul#categorymenu", {allowParentSelect: true});
<?php
	if ($objHi ->destination):
?>	
		var x = $("input[name='destination']").mcDropdown();
		x.setValue('<?php echo $objHi ->destination ?>');
<?php
	endif; 
?>
	}
});

</script>
<?php include("sidebar.php"); ?>
		<ul id="subnav" class="bar" >
			<li ><a href="highlight-list.php" > Highlight List </a></li>
			<li><font>&raquo;</font></li>
			<li class="noborder" ><span><?php echo $pTitle;?> </span></li>
		</ul>
<div id="list">
	<h2> <?php echo $pTitle;?> </h2>
			<form action="" method="post" name = "frmMain" id = "frmMain"   enctype="multipart/form-data"  >
			<fieldset><legend> General Info </legend>
					<table cellpadding="0" cellspacing="0" class="table-form"  >
						<tr>
							<th width="12%"  >Title: </th>
							<td width="88%" ><?php $objHi ->qText('title', '', 'width:548px', 'class="required"');?></td>
						</tr>
						<tr>
						<td colspan="2" >
						<br/>
							<label>Description: </label><?php $objHi ->qEditor('description', '', $config ); ?></td>
						</tr>
						<?php $objHi ->printSEO()  ?>
						<tr>
							<th>Destination: </th>
							<td>
							<?php
								if ($dropdown !== null){
									 $objHi ->qText('destination', 'null', 'width:548px', 'class=""');
									 echo $dropdown;
									 echo '<span class="note-small">select a region o diving center</span>';
								} else {
									echo '<strong style="color:#DF0000;">No exists region or diving center on database</strong>';
								}	  
							?>
							</td>
						</tr>
						<tr>
							<th>Picture : </th>
							<td>
						<?php	if ($objHi ->bgImage): ?>
								<div style="width: 230px;" class="img-border">
									<img alt="" src="../thumb.php?src=<?php echo TZN_FILE_UPLOAD_URL_ADMIN.$objHi ->bgImage?>&w=230&h=80" width="230" height="80"   ><br/>
									<a href="<?php echo $_SERVER['PHP_SELF']  ?>?action=del&id=<?php echo $objHi ->id ?>"  >delete picture</a>
								</div>
							<?php
								else:
									$objHi ->qFile('ifile', '', '', 'class="required"'); 		
								endif; 
							?>
							</td>
						</tr>
						<tr>
							<th>Status: </th>
							<td><?php $objHi ->arrayToSelect($objHi ->_arrStatus, 'status', $objHi ->status, false, 'width:100px', '');?></td>
						</tr>
					</table>
			</fieldset>
			<div style="margin-top:10px">
				<input type="hidden" name="id" value="<?php echo $id; ?>" />
				<input type="hidden" name="action" value="<?php echo $action; ?>" />
                <input type="submit" name="submit"  value="<?php echo $pButton; ?>" /> &nbsp; <input type="reset" value="Cancel" onClick="window.location.href='highlight-list.php'" />
            </div>
            </form>
</div>
<?php include("footer.php"); ?>